from flask import Blueprint, request, current_app as app

from app.model.base.RestResponse import RestResponse

from app.entity.master.Test import Test

web = Blueprint('test', __name__, url_prefix='/test')


@web.route('/index', methods=['GET'])
def index():
    t = Test.query.filter_by(id=5).first()
    # 集合
    return RestResponse().body(t.serialize())


@web.route('/postForm', methods=['POST'])
def postForm():
    app.logger.info('post data: %s', request.form)

    t = Test.query.filter_by(id=5).first()
    return RestResponse().body(t.serialize())


@web.route('/postJson', methods=['POST'])
def postJson():
    app.logger.info('post header: %s', request.headers)
    app.logger.info('post data1: %s', request.data)
    app.logger.info('post data2: %s', request.get_data())
    app.logger.info('post data3: %s', request.get_json())

    t = Test.query.filter_by(id=5).first()
    return RestResponse().body(t.serialize())
